package handler

import (
	"github.com/gin-gonic/gin"
	"log"
	"shop/shop-api/api/reponse"
	"shop/shop-api/api/request"
	"shop/shop-api/config"
	__ "shop/shop-srv/handler/proto"
)

func ShopAdd(c *gin.Context) {
	req := request.ShopAdd{}
	if c.ShouldBind(&req) != nil {
		reponse.Error(c, "绑定失败")
		return
	}
	r, err := config.ShopClient.ShopAdd(c, &__.ShopAddReq{
		Name:   req.Name,
		Price:  int64(req.Price),
		Number: int64(req.Number),
		Sales:  int64(req.Sales),
		Image:  req.Image,
		Status: req.Status,
	})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	reponse.Success(c, "添加成功", __.ShopAddResp{
		Id: r.Id,
	})
}
